#!/usr/bin/env node
const process = require("process");
const args = require("args");
const path = require("path");
let cwd = process.cwd();
console.log("cwd :", cwd);
let flags = args.parse(process.argv);
let sub = args.sub;
const getUploadPaths = require("./get_upload_paths").getUploadPaths;

const libup = require("../lib/360buyimg")

getUploadPaths(cwd, sub).then(async avai_paths => {
  let errors = [];
  for (let ap of avai_paths) {
    let o_up = await libup.uploadImage(ap.full_path);
    if (!o_up.ok) {
      errors.push(`${ap.full_path}:${o_up.msg}`);
      continue;
    }
    console.log(path.relative(cwd, ap.full_path));
    console.log(o_up.data.link);
  }
  if(errors.length){
    console.log("\n EROORS:")
    errors.forEach(e => console.error(e));
  }
  process.exit();
})